<?php

namespace app\controller;

use support\Request;
use support\View;
use think\facade\Db;
use app\model\Admin;

class Base
{
    public function beforeAction(Request $request)
    {
        //验证session
        //继承了Base的控制器优先验证此次session验证，然后才是AuthCheck验证
        $session = $request->session();
        if (!$session->get('token')) {
            return redirect('/');
        }

        //赋值当前菜单
        if (method_exists($this, '_infoModule')) {
            View::assign('infoModule', $this->_infoModule());
        }

        $session = $request->session();
        $this->assign('admin_id', $session->get('id'));
    }

    public function afterAction(Request $request, $response)
    {

    }

    protected static function checkToken($token)
    {
        $modelAdmin = new Admin;
        $where['token'] = $token;
        $infoMember = $modelAdmin->where($where)->find();
        return $infoMember;
    }

    protected function fetch($view)
    {
        return view($view);
    }

    protected function assign($param, $data = [])
    {
        View::assign($param, $data);
    }

}
